package com.wildlife.springboot.controller;

import com.wildlife.springboot.entity.EntityRelationship;
import com.wildlife.springboot.mapper.service.GraphService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/graph")
public class GraphController {

    @Autowired
    private GraphService graphService;

    // 获取所有实体关系
    @GetMapping("/relationships")
    public List<EntityRelationship> getEntityRelationships() {
        return graphService.getEntityRelationships();
    }

    // 增加实体关系
    @PostMapping("/relationship")
    public String addEntityRelationship(@RequestBody EntityRelationship entityRelationship) {
        return graphService.addEntityRelationship(entityRelationship);
    }

    // 删除实体关系
    @DeleteMapping("/relationship")
    public String deleteEntityRelationship(@RequestBody EntityRelationship entityRelationship) {
        return graphService.deleteEntityRelationship(entityRelationship);
    }

    // 根据实体查询所有相关关系
    @GetMapping("/relationships/{entity}")
    public List<EntityRelationship> getEntityRelationshipsByEntity(@PathVariable String entity) {
        return graphService.getEntityRelationshipsByEntity(entity);
    }
}

